package cn.source.web.controller.db;

import cn.source.common.core.domain.AjaxResult;
import cn.source.zk.domain.entity.FieldInfo;
import cn.source.zk.service.IDbFieldInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/db/fieldInfo")
public class DbFieldInfoController {

    @Autowired
    private IDbFieldInfoService fieldInfoService;

    /**
     * 根据表明获取表的字段列表
     * @param tableName
     * @return
     */
    @GetMapping("/list")
    public AjaxResult getFieldInfo(String tableName,String columnName) {
        List<FieldInfo> list = fieldInfoService.getFieldInfo(tableName);
        return AjaxResult.success(list.stream().filter(f->f.getField().toLowerCase().contains(columnName.toLowerCase())).collect(Collectors.toList()));
    }

}
